/**
 * fileName:  CategoryParamBean.java
 * author:  Lei
 * Company:  Cloudland Studio
 * Createdate:  2014-6-12 下午10:14:18
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-12          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.handler.support;

import java.util.List;

import org.cloudland.commercial.masterdata.bean.CategoryParam;
import org.cloudland.commercial.masterdata.bean.ChooseType;
import org.cloudland.commercial.masterdata.bean.RelationCost;
import org.cloudland.commercial.masterdata.bean.RelationParam;
import org.cloudland.commercial.masterdata.store.entity.ArgumentEntity;
import org.cloudland.commercial.masterdata.store.entity.CostEntity;
import org.cloudland.commercial.masterdata.store.entity.ParamValueRelEntity;
import org.cloudland.commercial.masterdata.store.read.ArgumentCostReader;
import org.cloudland.commercial.masterdata.store.read.ArgumentReader;

 /**
 * <pre> 
 * TODO 请充分描述该类提供的作用, 或与其他类会有关联的使用。
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  CategoryParamBean
 * @author  Lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
public class CategoryParamBean implements CategoryParam {
	
	/**
	 * relationBean 分类引用参数与值关系对象
	 */
	private ParamValueRelEntity relationBean;
	
	private boolean extend = false;
	
	/**
	 * argumentReader 参数查询接口
	 */
	private ArgumentReader argumentReader;
	
	/**
	 * costReader 值查询接口
	 */
	private ArgumentCostReader costReader;

	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *   
	 */
	public CategoryParamBean(ParamValueRelEntity relationBean, ArgumentReader argumentReader, ArgumentCostReader costReader) {
		this.relationBean = relationBean;
		this.argumentReader = argumentReader;
		this.costReader = costReader;
	}
	
	/**
	 * @return
	 */
	public String getRelationId() {
		return relationBean.getId();
	}
	
	/**
	 * @return
	 */
	public ChooseType getChooseType() {
		return relationBean.getChooseType();
	}
	
	/**
	 * @return
	 */
	public Integer getSort() {
		return relationBean.getSort();
	}
	
	/**
	 * set extend
	 * @param extend the value of extend
	 */
	public void setExtend(boolean extend) {
		this.extend = extend;
	}
	
	/**
	 * @return
	 */
	public Boolean isExtend() {
		return extend;
	}
	
	/**
	 * @return
	 */
	public RelationParam getRelationParam() {
		ArgumentEntity entity = argumentReader.findArgumentById(relationBean.getArgumentId());
		if (null == entity) {
			entity = new ArgumentEntity();
		}
		return new ArgumentBean(entity, null);
	}
	
	public String getRelationCostId() {
		return relationBean.getCostId();
	}

	/**
	 * @return
	 */
	public RelationCost[] getRelationCost() {
		
		if (null == relationBean.getCostId() || relationBean.getCostId().length() <= 0) {
			return new RelationCost[0];
		}
		
		List<CostEntity> arrayCost = costReader.findChildCostById(relationBean.getCostId());
		if (null == arrayCost || arrayCost.size() <= 0) {
			return new RelationCost[0];
		}
		
		ArgumentCostBean[] resultBeans = new ArgumentCostBean[arrayCost.size()];
		for (int i = 0; i < resultBeans.length; i++) {
			resultBeans[i] = new ArgumentCostBean(arrayCost.get(i), null, costReader);
		}
		return resultBeans;
	}

}
